import chardet

# 读取原文件并检测编码
with open('data.json', 'rb') as f:
    raw_data = f.read()
    detected_encoding = chardet.detect(raw_data)['encoding']
    print(f"检测到的编码: {detected_encoding}")

# 转换为 UTF-8 并保存
with open('data.json', 'r', encoding=detected_encoding, errors='replace') as f:
    content = f.read()

with open('data_utf8.json', 'w', encoding='utf-8') as f:
    f.write(content)

print("转换完成，新文件：data_utf8.json")